#ifndef __NET_H__
#define __NET_H__

#include "NetPrec.h"
#include "../Common/Thread.h"

const int SOMAXCONNECT     =20;
const int EPOLL_SIZE=(1024*4);
const int MAX_EVENT=(1024*4);
const int MAX_RECV_BUF_LEN= 8192*8;
const int MAX_SEND_BUF_LEN= 8192*8;

#ifndef _WIN32
#define USE_EPOLL
#endif

#ifdef _WIN32
#define SLEEP(a) Sleep(a)
#else
#define SLEEP(a) usleep((a)*1000)
#endif

class NetThread : public Thread
{
public:
	NetThread();
public:
	void run();
	bool Init();
	bool InitMasterSocket();
	bool Poll();
	void SetListeningPort(WORD port) {mListeningPort = port;}
	bool LoseConnect(SOCKET sock,struct epoll_event* ev);
private:
	int mMasterFd;
#ifdef USE_EPOLL
	int EpollFd; 
	struct epoll_event ev, events[EPOLL_SIZE];
#endif
	WORD mListeningPort;
	char RecvBuf[MAX_RECV_BUF_LEN];
	char SendBuf[MAX_SEND_BUF_LEN];
	volatile bool mExit;
};



#endif

